﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCDemo.Models;

namespace MVCDemo.Controllers
{
    public class HtmlHelpersController : Controller
    {
        public ActionResult Index()
        {
            MVCDemosEntities dbContext = new MVCDemosEntities();
            ViewBag.Departments = new SelectList(dbContext.Departments, "deptId", "deptName");

            List<SelectListItem> selectListItems = new List<SelectListItem>();

            foreach (Department department in dbContext.Departments)
            {
                SelectListItem selectListItem = new SelectListItem
                {
                    Text = department.deptName,
                    Value = department.deptId.ToString(),
                    Selected=department.IsSelected.HasValue?department.IsSelected.Value:false
                };

                selectListItems.Add(selectListItem);
            }

            ViewBag.DepartmentsWithSelection = selectListItems;
            return View();
        }

        public ActionResult Controls()
        {
            Company company = new Company("Calsoft");

            ViewBag.Departments = new SelectList(company.Departments, "deptId", "deptName");
            ViewBag.Company = company.CompanyName;

            return View();
        }

        public ActionResult Controls1()
        {
            Company company = new Company("Calsoft");

            return View(company);
        }
    }
}
